package dk.dmaa0912.boardgame;

import dk.dmaa0912.boardgame.R;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;

public class BoardMainActivity extends Activity {

	private CircleView board;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		
		board = new CircleView(this);
		setContentView(board);
		if (getIntent().getBooleanExtra("EXIT", false)) {
			 finish();
		}
		super.onCreate(savedInstanceState);
		
	}

	@Override
	protected void onResume() {
		super.onResume();
	}
	
	@Override
	protected void onPause() {
		super.onPause();
	}
	@Override
	protected void onStop() {
		super.onStop();
	}
	
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		
		super.onCreateOptionsMenu(menu);
		getMenuInflater().inflate(R.menu.board_main, menu);
		
		return true;
	}

	// Inflate the menu; this adds items to the action bar if it is present.
	@Override
	public boolean onOptionsItemSelected(MenuItem item) {	
	
		switch(item.getItemId())
		{
			case R.id.menu_pieces: 
				Intent toPieces = new Intent(this, Pieces.class);
				startActivityForResult(toPieces, 0);
				return true;
			case R.id.menu_email:
				Intent toEmail = new Intent(this, MailActivity.class);
				startActivity(toEmail);
				return true;
		
			default:
				return super.onOptionsItemSelected(item);
		}
	}
	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		super.onActivityResult(requestCode, resultCode, data);
		
		if(resultCode == RESULT_OK)
		{
			String color = data.getStringExtra("color");
			String text = data.getStringExtra("text");
			
			board.addPice(color, text);
	
		}
	}
}

